<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/11/23
 * Time: 13:25
 */
namespace hotel\modules\apiadmin\controllers;

use hotel\common\models\Comment;
use hotel\common\utils\Tool;
use \Yii;

class CommentController extends CoreController
{
	//列表
	public function actionList(){
		$get= \Yii::$app->request->get();
		$list = Comment::listsBack($get);
		return Tool::showRes([0, '成功'], $list);
	}
	//修改
	public function actionChange(){
		$post= \Yii::$app->request->post();
		$model = Comment::findOne($post['id']);
		if($model){
			unset($post['id']);
			$model->load(['Comment'=>$post]);
			if($model->save())
				return Tool::showRes([0, '成功']);
			else
				return Tool::showRes([400, '失败'],$model->errors);
		}
		return Tool::showRes([0, '缺少参数']);
	}
	//删除
	public function actionDel(){
		$post= \Yii::$app->request->post();
		$model = Comment::findOne($post['id']);
		if($model)
			$model->delete();
		return Tool::showRes([0, '成功']);
	}
}